The present invention relates to an apparatus and method used for rounding that is necessary for analyses, measurements, investigations, and so on. More particularly, the invention relates to an apparatus and method for performing rounding processing according to significant digits or a rounding interval.
Generally, rounding processing typified by rounding off has enjoyed wide acceptance. Examples include reorganization of experimental data and accounting processes. Many rounding processes are prepared as functions in high-level languages and data-processing software. A user can obtain rounded a numerical value by specifying a numerical value and a digit place to be processed.
FIG. 14 illustrates processing performed using a conventional rounding function. First, a user enters a numerical value x to be processed and a digit place p to be processed (step 601). If the digit place p to be processed is the place of 100, for example, p is xe2x88x922. If an integer should be derived, p is 0. If the digit place is the third decimal place, p is +3. Then, the digits in the successive digit places of the given numerical value x are stored in turn in memory (step 602). A digit in the digit place immediately to the right of the specified digit place p is read from the memory (step 603). A decision is made as to whether the digit is equal to or greater than 5 (step 604). If the result of the decision is YES (i.e., the numerical value is equal to or greater than 5), rounding up is performed (step 605). If the result of the decision is NO, rounding down is performed (step 606). In this way, the conventional conditional branching processing using a function takes out only one digit from digits in plural digit places. Then, a conditional branch is effected.
The prior art technique described above has the following problems.
(1) It is impossible to specify the processed digit place by significant digits.
Spreadsheet software programs presently available on the market do not have the concept that the processed digit place is specified by significant digits. If a digit place to be processed is counted from the leftmost digit place and specified, other conditional branching processing is necessary so that the processed digit place is specified by significant digits across a decimal point, as long as the prior art conditional branching processing is performed (i.e., only one digit is taken from plural digit places and a decision is made). For example, where 0.0000234 should be rounded to two significant digits, if this numerical value is counted as it is, then the digit in the third decimal place will be taken and a rounding process will be performed. Therefore, digits are taken in turn from the leftmost digit place and counted. A decision is made as to whether each taken digit is 0 or not. If it is 0, this digit place is not counted. In this way, conditional branching processing is needed. Furthermore, where a rounding process is executed with four significant digits, if the numerical value is 30200, xe2x80x9c0xe2x80x9d in the fourth digit place, xe2x80x9c0xe2x80x9d in the second digit place, and xe2x80x9c0xe2x80x9d in the first digit place all need to be counted. In the case of 0.34502, xe2x80x9c0xe2x80x9d in the first digit place(the most significant digit) is not counted. However, xe2x80x9c0xe2x80x9d in the fourth decimal place and so on must be counted. Therefore, more conditional branches are necessary.
Where the prior art processing sequence as described above is used, if the digit to be rounded is specified by significant digits, very complicated processing inevitably takes place. For this reason, the prior art function does not make it possible to specify a digit place by significant digits. Furthermore, any spreadsheet software capable of specifying a desired digit place by a significant number is not available.
(2) Rounding processing directly using a rounding interval cannot be performed.
Rounding using a rounding interval is based on ISO (International Standards Organization) 31-0:1992(E), appendix B, xe2x80x9cGuide to the rounding of numbersxe2x80x9d. Rounding using a rounding interval is to replace a given numerical value by a numerical value selected from a sequence of integral multiples of a chosen rounding interval. For instance, where the rounding interval is 0.1, 12.849 is rounded to 12.8 and 13.451 is rounded to 13.5. Where the rounding interval is 10, 1284.9 is rounded to 1280, and 1345.1 is rounded to 1350. Accordingly, in rounding processing using a rounding interval, what is entered first is not the processed digit place but a rounding interval. However, spreadsheet software programs currently available on the market do not have the concept that rounding is performed based on a rounding interval. Hence, it has been impossible to perform a rounding process by directly entering a rounding interval. Therefore, in order to perform the prior art rounding process using a rounding interval, additional processing for converting the rounding interval to the processed digit place is necessary. This complicates the processing, and the processing time is prolonged.
(3) It is impossible to cope with JIS (Japanese Industrial Standard).
Where simple rounding off is used, the result is biased according to the numerical values contained in the data. Therefore, rounding for correcting the biased result and minimizing the round-off error is necessary. JIS stipulates a rounding method for that purpose. Many materials submitted to the public agencies have numerical values that must be rounded in accordance with JIS.
FIG. 15 illustrates a rounding method stipulated by JIS, Z8401. Fundamentally, a round-off process is performed, and the remaining 5 is sorted. Where a numerical value is rounded to a numerical value having n significant digits, a digit in the (n+1)th place and less significant digits are reorganized as follows.
(a) Where a digit in the (n+1)th digit place or a less significant digit is less than half of 1 unit in the nth digit place, the digit is dropped.
(b) Where a digit in the (n+1)th digit place or a less significant digit is in excess of half of 1 unit in the nth digit place, the digit in the nth digit place is increased by 1 unit.
(c) Where the digit in the (n+1)th place or a less significant digit is equal to half of 1 unit in the nth digit place, the following processes (i) and (ii) are carried out.
(i) If the digit in the nth digit place is 0, 2, 4, 6, or 8, the digit is dropped.
(ii) If the digit in the nth digit place is 1, 3, 5, 7, or 9, the digit in the nth place is increased by 1 unit.
Significant digits are counted from the place of the most significant digit that is nonzero. This rounding must be performed in one stage. For example, if 5.346 is rounded to two significant digits by this method, then 5.3 results. If the rounding is done in two stages, the numerical value is rounded to 5.35 in the first stage and to 5.4 in the second stage.
The processing is conducted in the sequence in the manner described below. First, the number of digits is judged (step 701). A decision is made as to whether the digit in the (n+1)th digit place is 6 or more (step 702). If the digit is 6 or more, the digit in the nth digit place is increased by 1. The digit in the (n+1)th place and less significant digits are dropped (step 706). For example, if 13.461 is rounded to three significant digits, 13.5 results.
Then, a decision is made as to whether the digit in the (n+1)th digit place is 4 or less (step 703). If it is 4 or less, the digit in the (n+1)th place and less significant digits are dropped (step 707). For example, if 12.849 is rounded to three significant digits, 12.8 is derived.
If the digit in the (n+1)th place is neither equal to or greater than 6 nor equal to or less than 4, i.e., the digit in the (n+1)th digit place is 5, a decision is made as to whether the digit in the (n+2)th place and less significant digits are all 0 (step 704). If the digit in the (n+2)th place and less significant digits contain nonzero numeral or numerals, the digit in the nth digit place is increased by 1, and the digit in the (n+1)th place and less significant digits are deleted (step 706). For example, if 13.451 is rounded to three significant digits on this principle, 13.5 results.
If the digit in the (n+2)th digit place and less significant digits are all 0, a decision is made as to whether the digit in the nth place is even or odd (step 705). If the result is that the digit is even, then the digit in the (n+1)th place and less significant digits are deleted (step 707). For example, if 11.450 is rounded to three significant digits, 11.4 results. Conversely, if the digit in the nth place is odd, the digit in the nth place is increased by 1, and the digit in the (n+1)th place and less significant digits are dropped (step 706). For instance, if 12.750 is rounded to three significant digits, 12.8 arises.
However, if digits necessary for decision are taken from all the digit places of the digits as in the conditional branching processing using the prior art round-off function, and if the taken digits are treated as one number, numerous conditional branches (steps 804-807) are necessary in the conditional branching of step 704 of FIG. 15, as illustrated in FIG. 16.
This portion is used to judge that the digit in the (n+1)th digit place is 5 and that the less significant digits are all 0. Where necessary digits are extracted from all digit places and treated as one number, the digits in all the digit places must be judged.
For example, where digits located to the right of a rounded digit are 50000001, JIS demands rounding up. If a human makes a decision by his eyes, he can immediately sense that a nonzero digit is present in some less significant digit place. Where a computer is used, the method of decision presents a problem. In the prior art processing where a decision is made for each digit place, a decision is made as to whether the digit in the (n+2)th digit place 0 or not. Then, a decision is made as to whether the digit in the (n+3)th place is 0 or not. Subsequently, a decision is made as to whether the digit in the (n+4)th place is 0 or not. In this way, decisions are made up to the rightmost digit place to judge whether 0 is not contained at all in the (n+2)th and the following places or any nonzero numeral is present in any digit place. Since the digits in the successive digit places are judged in turn, the final judgment cannot be made until a multiplicity of branching operations are carried out.
Where the number of digits capable of being calculated by the today""s computer is contemplated, it is expected that the number of the conditional branch operations will be exorbitant. Accordingly, in the conventional procedure, it is necessary to limit the number of treated digits to far below the processing capability of the computer to reduce the number of the necessary conditional branch operations. Therefore, even if the procedure is treated in terms of software, calculation is urged to be performed at a level considerably lower than the computer""s computational capability. This narrows the range that can be processed. As a result, the software would not be viable on the market. In this way, the present situation is that any software capable of performing rounding operations in accordance with JIS Z8401 has not been developed or put into practice.
In the rounding processing described above, it is impossible to directly enter a rounding interval for rounding processing. In order to perform the prior art rounding process using a rounding interval, additional processing for converting the rounding interval into a digit place is necessary. Also, in this case, the processing is complicated and the processing time is prolonged.
It is an object of the present invention to provide an apparatus and method capable of performing a rounding process by rounding a numerical value, using significant digits or a rounding interval as it is.
It is another object of the invention to provide an apparatus and method capable of rounding numbers with minimum round-off error as in accordance with JIS (Japanese Industrial Standard), using significant digits or a rounding interval as it is.
A rounding apparatus in accordance with the present invention comprises an input portion for entering a numerical value x to be rounded and the number of significant digits n or a rounding interval w, a first storage portion for storing the entered numerical value x, a second storage portion for storing the entered number of significant digits n or rounding interval w, and a rounding processing portion for rounding the numerical value x stored in the first storage portion in a digit place specified by the number of significant digits n or rounding interval w stored in the second storage portion. This apparatus can round the numerical value while using the number of significant digits or rounding interval as it is.
Other objects and features of the invention will appear in the course of the description thereof, which follows.